<? require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php"); ?>

<?
if (!CModule::IncludeModule("iblock"))
{
    echo "Не установлен модуль Информационных-блоков";
    die();
}

// функции для работы с MSSQL
class DBase
{
    var $host;
    var $username;
    var $password;
    var $bsname;

    var $result;
    var $num_rows;
    var $num_cols;
    var $row;

    function DBase($dbhost,$dbusername,$dbpassword,$dbbasename)
    {
            $this->host = $dbhost;
            $this->username = $dbusername;
            $this->password = $dbpassword;
            $this->bsname = $dbbasename;
            mssql_connect($this->host,$this->username,$this->password) or
                    die( "Нельзя подключиться к базе данных" );
            mssql_select_db($this->bsname);

    }

    function sql($sql)
    {
            return mssql_query($sql) or die ( "Неверный запрос: $sql<br>" );
    }

    function select($sql)
    {
            $this->result = mssql_query($sql) or die ( "Неверный запрос: $sql<br>" );
            $this->num_rows = mssql_num_rows($this->result);
            $this->row = 0;
            $this->num_cols = mssql_num_fields($this->result);
            return mssql_fetch_object($this->result);
    }

    function next()
    {
            $this->row++;
            return mssql_fetch_object($this->result);
    }

    function numrows()
    {
            return $this->num_rows;
    }

    function numcols()
    {
            return $this->num_cols;
    }

    function eof()
    {
            return $this->row == $this->num_rows;
    }

    function fields()
    {
            $i = 0;
            while ( $i < $this->num_cols )
            {
                    $arr[$i][0] = mssql_field_name($this->result,$i);
                    $arr[$i][1] = mssql_field_type($this->result,$i);
                    $arr[$i][2] = mssql_field_len($this->result,$i);
                    $arr[$i][3] = mssql_field_flags($this->result,$i);
                    $i++;
            }
            return $arr;
    }

    function close()
    {
            if ($this->result != null) mssql_free_result($this->result);
            mssql_close();
    }
}    

function Encode($str)
{
    static $table = array(
    "\xA8" => "\xD0\x81",
    "\xB8" => "\xD1\x91",
    "\xA1" => "\xD0\x8E",
    "\xA2" => "\xD1\x9E",
    "\xAA" => "\xD0\x84",
    "\xAF" => "\xD0\x87",
    "\xB2" => "\xD0\x86",
    "\xB3" => "\xD1\x96",
    "\xBA" => "\xD1\x94",
    "\xBF" => "\xD1\x97",
    "\x8C" => "\xD3\x90",
    "\x8D" => "\xD3\x96",
    "\x8E" => "\xD2\xAA",
    "\x8F" => "\xD3\xB2",
    "\x9C" => "\xD3\x91",
    "\x9D" => "\xD3\x97",
    "\x9E" => "\xD2\xAB",
    "\x9F" => "\xD3\xB3",
    );
    return preg_replace('#[\x80-\xFF]#se',
    ' "$0" >= "\xF0" ? "\xD1".chr(ord("$0")-0x70) :
                       ("$0" >= "\xC0" ? "\xD0".chr(ord("$0")-0x30) :
                        (isset($table["$0"]) ? $table["$0"] : "")
                       )',
    $str
    );
}

function GetUserPhoto($userid)
{
    $imgPath = "http://10.15.140.3/UserPhotos/".$userid.".jpg";
    if (!file_get_contents($imgPath))
    {
       $rsUser = CUser::GetByLogin($userid);
       if($arUser = $rsUser->Fetch())
       {
           if ($arUser["PERSONAL_PHOTO"]>0)
           {
               $arFile = CFile::GetFileArray($arUser["PERSONAL_PHOTO"]);
               $imgPath = $arFile["SRC"];
           }
           else
               $imgPath = "/bitrix/images/socialnetwork/nopic_user_150.gif";
       }
       else
           $imgPath = "/bitrix/images/socialnetwork/nopic_user_150.gif";                    
    }
    return $imgPath;
}

$host = "10.15.140.3";
$username = "sa";
$password = "admin";
$dbname = "PayDox";
$dbase = new DBase($host,$username,$password,$dbname);

// ***********************************
// выбираем предустановленные значения
// ***********************************

$showOther = false;



// выбираем все остальное
$items = CIBlockElement::GetList(Array("SORT"=>"ASC"), Array("IBLOCK_ID"=>"1", "!ID"=>Array("2862", "2863", "2864", "2865", "2866", "3383", "3387")), false, false, Array("ID", "NAME", "PREVIEW_PICTURE", "DETAIL_PICTURE", "PREVIEW_TEXT", "PROPERTY_INTERVAL"));
while ($item = $items->GetNext())
{
    if ($item["PREVIEW_PICTURE"])
        $item["PREVIEW_PICTURE"] = CFile::GetFileArray($item["PREVIEW_PICTURE"]);
    if ($item["DETAIL_PICTURE"])
        $item["DETAIL_PICTURE"] = CFile::GetFileArray($item["DETAIL_PICTURE"]);
    
    $item["INTERVAL"] = $item["PROPERTY_INTERVAL_VALUE"];
    
    $info[] = $item;
}
if (count($info))
    $showOther = true;


?>


<div id="slider_box">
    <div id='slider_left_box'>
        <div id="carousel2" class="jcarousel-skin-tango-2">
                <div class="jcarousel" id="jcarousel2">
                        <ul>                           
                            <? if ($showOther): ?>
                            <? foreach ($info as $el): ?>
                            <li interval='<?= $el["INTERVAL"]; ?>'>
                                <h2><?= $el["NAME"]; ?></h2>
                                
                                <? if (strlen($el["DETAIL_PICTURE"]["SRC"])): ?>
                                <div class="info_img">
                                    <img src='<?= $el["DETAIL_PICTURE"]["SRC"]; ?>' />
                                <? else: ?>
                                <div class="info">
                                    <? if (strlen($el["PREVIEW_PICTURE"]["SRC"])): ?>
                                        <img src='<?= $el["PREVIEW_PICTURE"]["SRC"]; ?>' />
                                    <? endif; ?>
                                    <?= $el["PREVIEW_TEXT"]; ?>
                                <? endif; ?>
                                </div>
                            </li>
                            <? endforeach; ?>
                            <? endif; ?>
                            
                        </ul>
                </div>
                <div class="jcarousel-pagination" id="jcarousel-pagination"></div>
        </div>
    </div>
</div>    

<div class="countdown"></div>
<div id="hours">
    <script language="JavaScript" type="text/javascript" src="/plazma/date.js"></script>
</div>
    
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>
